<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.chengxiaoxiao.commons.PageUtils" %>
<%@ page import="com.chengxiaoxiao.commons.Page" %>
<%@include file="/commons/header.jsp" %>


<div style="margin-left:210px;margin-top:65px;padding:10px 5px 0 5px;">

    <div style="line-height:26px;height:26px;margin-bottom:10px;">
        <h1 style="float:left;font-size:26px;">分类管理</h1>

        <span class="layui-breadcrumb" style="float:right;font-size:12px;">
                <a href="#">首页</a>
                <a><cite>分类管理</cite></a>
            </span>
    </div>


    <!--内容-----------------------------开始-------------------------------------------------->
    <div style="clear:both;margin-top:20px; float:right;">
        <a id="add" class="layui-btn layui-btn-normal" href="javascript:void(0);">添加</a>
    </div>


    <table class="layui-table" lay-skin="row">
        <thead>
        <tr>
            <th>序号</th>
            <th>分类名称</th>
            <th>分类描述</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        <c:forEach items="${list}" var="b" varStatus="vs">
            <tr>
                <td width="7%">${vs.count}</td>
                <td width="15%">${b.name}</td>
                <td>${b.descript}</td>

                <td>
                    <button ids="${b.id}" class="layui-btn layui-btn-normal layui-btn-small edit"><i
                            class="layui-icon"> &#xe642;</i></button>
                    <button ids="${b.id}" class="layui-btn layui-btn-normal layui-btn-small delete"><i
                            class="layui-icon"></i></button>
                </td>
            </tr>
        </c:forEach>


        </tbody>

    </table>

    <br/><br/><br/><br/><br/><br/><br/><br/>

    <div id="demo1" style="margin-top:10px;"></div>


    <script type="text/javascript">

        $(function () {

            //编辑图书
            $('#add').on('click', function () {
                var item = $(this);
                var ids = item.attr("ids");

                layer.open({
                    type: 2,
                    title: '新建分类信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '520px'],
                    content: '${pageContext.request.contextPath}/book/addCatrgory.jsp'
                });
            });

            //编辑
            $('.edit').on('click', function () {
                var item = $(this);
                var ids = item.attr("ids");

                layer.open({
                    type: 2,
                    title: '编辑分类信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '520px'],
                    content: '${pageContext.request.contextPath}/manager/BookServlet?op=showeditcategory&id=' + ids
                });
            });


            //删除逻辑
            $(".delete").click(function () {


                var check = confirm("确认要删除吗？");

                if (!check) {
                    return;
                }
                var item = $(this);

                var id = item.attr("ids");

                $.post("${pageContext.request.contextPath}/manager/BookServlet?op=deleteCategory", {"id": id}, function (data) {

                    var $dom =JSON.parse(data);


                    layer.msg($dom["error"]);
                    window.location = "${pageContext.request.contextPath}/manager/BookServlet?op=listcategory";

                });
            });

        });
    </script>


    <script src="${pageContext.request.contextPath}/lib/layui.all.js"></script>


<%@include file="/commons/footer.jsp" %>